import $ from '../common';
Page({
  data: {
    multiArr:[[],[]],
    multiIndex:['','']
  },
  onLoad(e) {
    this.setData({
     campus_uuid:e.uuid
    })
    this.getinfo()
  },
  onShow() {

  },
  getinfo(){
    $.get('/campus/studygrades/arrary',{
      campus_uuid:this.data.campus_uuid
    },res=>{
      $.get('/campus/schoolclass',{
        campus_uuid:this.data.campus_uuid,
        studygrade:res.grades[0].key
      },ras=>{
        let json = JSON.parse(JSON.stringify(res.grades).replace(/value/g,"name"));
        this.setData({
          'multiArr[0]':json,
          'multiArr[1]':ras.schoolclass
        })
      })
    })
  },
  bindMultiPickerChange(e){
    if(this.data.multiArr[1].length>0){
      $.parent().setData({
        'info.schoolclass_name':this.data.multiArr[1][e.detail.value[1]||0].name,
        'info.schoolclass_uuid':this.data.multiArr[1][e.detail.value[1]||0].uuid,
      })
      $.navigateBack()
    }
  },
  bindMultiPickerColumnChange(e){
    if(e.detail.column==0){
      $.get('/campus/schoolclass',{
        campus_uuid:this.data.campus_uuid,
        studygrade:e.detail.value
      },res=>{
        this.setData({
          'multiArr[1]':res.schoolclass
        })
      })
    }
  }
})